Ext.define('WebOs.ex.ModalWindow', {
	extend : 'Ext.window.Window',
	
	modal : true,
	depth : null,
	parent : null,
	surportVF : ['desktop'],
	ancestor : null,
	exist : false,
	constructor : function(config) {
		var me = this;
		Ext.apply(me, config);
		if(config.parent){
			me.parent = config.parent;
			if(Ext.getClassName(me.parent) == 'WebOs.ViewFrame.desktop.view.DesktopWindow'){
				me.depth = 1;
				me.ancestor = me.parent;
			}else{
				me.depth = me.parent.depth + 1;
				me.ancestor = me.parent.ancestor;
			}
		};
		me.callParent(arguments);
	},
	initComponent : function() {
		var me = this;
		Ext.applyIf(me,arguments);
		
		me.on(
			{
				show : function(cmp){
					if(me.exist){
						return;
					}
					if(me.ancestor){
						me.ancestor.registerModalWindow(cmp); 
						me.exist = true;
					}
				},
				destroy : function(cmp){
					if(me.ancestor){
						me.ancestor.removeModalWindow(cmp); 
					}
				}
			}
		);
		me.callParent(arguments);
	},
	hasParent : function(){
		var me = this;
		if(me.parent){
			return true;
		}
			return false;
	}
});